<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>品类元数据管理</title>
        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel" style="border:none;">
               <form id="ff">      
                <div style="margin-bottom:20px">
                  <label class="item-label">品类：</label>
                  <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width: 100px;">
                  </select>
                  <label class="item-label">名称：</label>
                  <input type="text" name="name" class="easyui-textbox" style="width: 100px;" />
                  <label class="item-label">类型：</label>
                  <select name="type" class="easyui-combobox" style="width: 100px;" data-options="panelHeight:'auto'">
                      <option value="">-请选择-</option>
                      <option value="INPUT">文字</option>
	                  <option value="BOOLEAN">布尔</option>
	                  <option value="NUMBER">数字</option>
	                  <option value="SELECTED">单选</option>
                      <option value="MULTI">多选</option>
                  </select>
                  <label class="item-label">可选值：</label>
                  <input type="text" name="tags" class="easyui-textbox" style="width: 100px;" />
                  <label class="item-label">是否必填：</label>
                  <select name="require" class="easyui-combobox" style="width: 100px;" data-options="panelHeight:'auto'">
                    <option value="">-请选择-</option>
                    <option value="true">是</option>
                    <option value="false">否</option>
                  </select>
                  <label class="item-label">状态：</label>
                    <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >
                  <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px;margin-left: 40px;" onclick="searchBy()">查询</a>
                </div>
                </form>
            </div>
            <div class="table-wrapper">
             <table id="datagrid" data-options="fitColumns:true,scrollbarSize:0">
               <thead>
                 <tr>
                   <th data-options="field:'categoryName',align:'center'" width="100">品类</th>
                   <th data-options="field:'name',align:'center'" width="100">规格名称</th>
                   <th data-options="field:'code',align:'center'" width="100">规格编码</th>
                   <th data-options="field:'type',align:'center', formatter:typeFormatter" width="100">数据类型</th>
                   <th data-options="field:'values',align:'center'" width="240">可选值</th>
                   <th data-options="field:'require',align:'center',formatter:boolFormatter" width="80">是否必填</th>
                   <th data-options="field:'fisrtLevelMetadata',align:'center',formatter:boolFormatter" width="80">一级规格</th>
                   <!--<th data-options="field:'values',align:'center', " width="240">新品规格</th>-->
                   <!--<th data-options="field:'newModelMetadata',align:'center'" width="80">序号</th>-->
                   <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>
                   <th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th>
                 </tr>
               </thead>
               <tbody>
               </tbody>
             </table>
           </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript" src="/webapp/js/common/pagelist.js"></script>
    <script type="text/javascript">
        function initPage(){
            initUserCategorySelect("categorySelect", null, function(){
                var categoryCode = getQueryParameter("categoryCode");
                if(categoryCode){
                    // 其它页面跳过来传弟的值
                    $("#ff").form("load", {'categoryCode': categoryCode});
                }
            });
        }
        $(function(){
            initPage();
            var height = $(window).height();
            var nav_height = $("#nav")._outerHeight();
            var ff_height = $("#ff").height();
            var table_height = height-nav_height-ff_height-40;
            $("#datagrid").css("max-height",table_height);
            $("#datagrid").datagrid({
                toolbar:[{
                    text:"添加品类元数据",
                    handler:function(){
                        var category = getFormData(document.getElementById("ff")).categoryCode;
                        if(category){
                            window.parent.addTab("添加品类元数据","/webapp/pages/product/categoryMetadata/add.html?categoryCode="+category);
                        }else{
                            $.messager.alert("提示","请选择品类","warn");
                        }
                    }
                }, '-', {
                    text: "编辑规格位置",
                    handler: function () {
                        var category = getFormData(document.getElementById("ff")).categoryCode;
                        window.parent.addTab("编辑规格位置","/webapp/pages/product/categoryMetadata/position.html?categoryCode="+category);
                    }
                }]
            });
        });

        $(function () {
            setNav();
            var url = config.url + getModuleName();
            $("#ff").keydown(function (event) {
                var e = event || window.event;
                var keyCode = e.keyCode || e.which;
                if(keyCode=="13"){
                    searchBy();
                }
            });
            var initPage = window.initPage||function () {
                var dtd = $.Deferred();
                setTimeout(function () {
                    dtd.resolve();
                },500);
                return dtd.promise();
            };
            $.when(initPage()).done(function () {
                var queryParams = getFormData(document.getElementById("ff"));
                queryParams = transfer(queryParams);
                $("#datagrid").datagrid({
                    pagination:true,
                    rownumbers:true,
                    url:url,
                    method:'get',
                    queryParams:queryParams
                });
            });
            aRecords("品类元数据","/webapp/pages/product/categoryMetadata/")
        });


        var typeObj = {
            "INPUT":"文本", "BOOLEAN":"布尔值", "NUMBER": "数值" , "SELECTED": "单选值" ,"MULTI":"多选值"
        }
        function typeFormatter(val, row){
            return !!typeObj[val]?typeObj[val]:val;
        }
        function actions(val,row,index){
            var text = row.entityStatus=="OK"?"禁用":"启用";
            return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
                "onclick='edit(\""+row.id+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;"+
                "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
                "onclick='updateStatus(\""+row.id+"\",\""+row.entityStatus+"\")'>"+text+"</a>";
        }
        function edit(id,categoryCode){
            window.parent.addTab("修改元数据","/webapp/pages/product/categoryMetadata/add.html?id="+id+"&categoryCode=" + categoryCode);
        }
        function searchBy() {
            var queryParams = $("#datagrid").datagrid("options").queryParams;
            var entityStatus=document.getElementById('entityStatus');
            if (entityStatus) {
                queryParams.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
            }
            var formData = getFormData(document.getElementById("ff"));
            var params = formData;//transfer(formData);
            for(var i in params){
                queryParams[i] = params[i];
                if(!queryParams[i]){
                    delete queryParams[i];
                }
            }
            $("#datagrid").datagrid("reload");
        }
    </script>

</html>
